package demo4;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] nums1={0};
        int[] nums2={1};
        Solution solution = new Solution();
        solution.merge(nums1,0,nums2,1);
        System.out.println(Arrays.toString(nums1));
    }
}
class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(nums1[j]>nums2[i]){
                    for (int k = nums1.length-2; k >= j; k--) {
                        nums1[k+1]=nums1[k];
                    }
                    nums1[j]=nums2[i];
                    m++;
                    break;
                }
            }
            if(m!=0&&nums1[m-1]<=nums2[i]){
                nums1[m]=nums2[i];
                m++;
            }else if(m==0){
                nums1[0]=nums2[i];
                m++;
            }

        }
    }
}